<template>
  <div class="page-container">
    <div class="container">
    <h1>员工变更历史</h1>
    <el-input
        v-model="searchKeyword"
        placeholder="请输入关键词搜索"
        style="margin-bottom: 20px; width: 300px; border-radius: 20px;"
        @keyup.enter="handleSearch"
    >
      <template #suffix>
        <el-button  @click="handleSearch" style="border-radius: 20px;">查询</el-button>
      </template>
    </el-input>
    <el-table :data="employeeChanges" style="width: 100%">
      <el-table-column label="ID" prop="id" width="180"></el-table-column>
      <el-table-column label="员工ID" prop="employeeId" width="180"></el-table-column>
      <el-table-column label="员工真名" prop="employeeName" width="180"></el-table-column>
      <el-table-column label="职位变更历史" prop="positionChangeHistory"></el-table-column>
    </el-table>

  <el-pagination
      background
      layout="prev, pager, next"
      :total="pagination.total"
      :page-size="pagination.size"
      v-model:current-page="pagination.page"
      @current-change="fetchEmployees"
      style="margin-top: 20px; text-align: center;"
  />
    </div>
  </div>
</template>

<script setup>
import {ref, onMounted} from 'vue';
import axios from 'axios';
const searchKeyword = ref('');
const employeeChanges = ref([]);
const pagination = ref({
  page: 1,
  size: 10,
  total: 0,
});

onMounted(() => {
  fetchEmployees();
  // 可以在这里做一些初始化操作
});
const fetchEmployees=async () => {
  try {
    const response = await axios.get('http://localhost:8080/admin/employee_changes', {
      params: {
        page: pagination.value.page,
        size: pagination.value.size,
        keyword: searchKeyword.value,
      },
    });
    employeeChanges.value = response.data.data.records;
    pagination.value.total = response.data.data.total;
  } catch (error) {
    console.error('Error fetching data:', error);
  }
}
const handleSearch = () => {
  pagination.value.page = 1;
  fetchEmployees();
};
</script>

<style scoped>
.container {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
/* Add your styles here */
</style>